//
//  SDCycleBgView.m
//  delongzhitou
//
//  Created by Mr.Wang on 2018/12/17.
//  Copyright © 2018 delongzhitou. All rights reserved.
//

#import "SDCycleBgView.h"
#import "DLMachineCycleModel.h"


@interface SDCycleBgView()<SDCycleScrollViewDelegate>

@property (nonatomic, strong) SDCycleScrollView *sdScroll;

@end

@implementation SDCycleBgView


- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self layoutSubControls];
        self.backgroundColor = [UIColor whiteColor];
        
    }
    return self;
}
- (void) layoutSubControls {
    
    SDCycleScrollView *sdScroll = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(10, 15, self.width - 20,kAutoWidth(134) - 15) delegate:self placeholderImage:[UIImage imageNamed:@"defaultImg"]];
    sdScroll.backgroundColor = [UIColor whiteColor];
    sdScroll.localizationImageNamesGroup = @[];
    sdScroll.pageControlStyle = SDCycleScrollViewPageContolStyleClassic;
    sdScroll.pageDotColor = kDLBtnNormalBgColor;
    sdScroll.autoScrollTimeInterval = 5;
    sdScroll.contentMode = UIViewContentModeScaleAspectFill;
    sdScroll.clipsToBounds = YES;
    [self addSubview:sdScroll];
    self.sdScroll = sdScroll;
    sdScroll.imageURLStringsGroup = @[];
}
- (void) setCycleDataSource:(NSArray *)cycleDataSource {
    _cycleDataSource = cycleDataSource;
    if (cycleDataSource.count > 0) {
        
        NSMutableArray *mutUrlArr = [NSMutableArray array];
        for (NSInteger i = 0; i < cycleDataSource.count; i++) {
            DLMachineCycleModel *model = cycleDataSource[i];
            NSString *imageUrl = [NSString stringWithFormat:@"%@", model.picUrl];
            [mutUrlArr addObject:imageUrl];
        }
        self.sdScroll.imageURLStringsGroup = mutUrlArr;
    }
}
- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index;{
    //首页轮播图
    DLMachineCycleModel *model = self.cycleDataSource[index];
    NSLog(@"点击的图片的链接是：%@", model.picLink);
    NSString *urlString = [NSString stringWithFormat:@"%@", model.picLink];
    if ([urlString containsString:@"null"]) {
        return;
    }
    
    
    DLNormalWebVC *bvc = [DLNormalWebVC new];
    bvc.urlString = model.picLink;
    bvc.webViewType = DLWebViewType_wholeUrl;
    [kuserManager.lastVc.navigationController pushViewController:bvc animated:YES];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
